package it.univaq.mwt.backoffice.action;

import it.univaq.mwt.business.CategoryService;
import it.univaq.mwt.business.GroupsService;
import it.univaq.mwt.business.UserService;
import it.univaq.mwt.common.business.CategoryServiceFactory;
import it.univaq.mwt.common.business.GroupsServiceFactory;
import it.univaq.mwt.common.business.UsersServiceFactory;
import it.univaq.mwt.exceptionmonitor.WishlistUserException;
import it.univaq.mwt.exceptionmonitor.WishlistrMessage;
import it.univaq.mwt.log.LivelloLog;
import it.univaq.mwt.log.LogManager;
import it.univaq.mwt.model.entity.Category;
import it.univaq.mwt.model.entity.Groups;
import it.univaq.mwt.model.entity.Users;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.MappingDispatchAction;

public class ManageStartupAction extends MappingDispatchAction implements LivelloLog{

	public ActionForward startupAct(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
	
		GroupsServiceFactory groupsFactory=GroupsServiceFactory.getInstance();
		GroupsService facadeGroups=groupsFactory.getGroupsService();
		
		UsersServiceFactory userFactory = UsersServiceFactory.getInstance();
		UserService facadeUser = userFactory.getUserService();
		
		CategoryServiceFactory categoryFactory=CategoryServiceFactory.getInstance();
		CategoryService facadeCategory=categoryFactory.getCategoryService();
		
		Groups admin=new Groups();
		Groups logged=new Groups();
		
		Users user=new Users();
		Category cat1=new Category();
		Category cat2=new Category();
		Category cat3=new Category();
		Category cat4=new Category();
		Category cat5=new Category();
		try{
		
		admin.setName("admin");
		Groups adm= facadeGroups.addGroup(admin);
		
		logged.setName("logged");
		facadeGroups.addGroup(logged);
		
		
		if(adm!=null){
			user.setName("admin");
			user.setPassword("admin");
			user.setUsername("admin");
			user.setEmail("admin@macaguma.it");
			user.setGroups(adm);
			facadeUser.addUserStartup(user);
		}
		
		
		cat1.setName("private");
		facadeCategory.addCategory(cat1);
		cat2.setName("technology");
		facadeCategory.addCategory(cat2);
		cat3.setName("sport");
		facadeCategory.addCategory(cat3);
		cat4.setName("beauty");
		facadeCategory.addCategory(cat4);
		cat5.setName("other");
		facadeCategory.addCategory(cat5);
		}
		catch(WishlistUserException e){
			LogManager.getIstance().scrivi("ManageStartupAction - startupAct : " + e.getMessage() ,ERR);
		}
		return mapping.findForward("success");
		
	
		
		
		
		
		
	}
	
}
